function preparray1() {
$.post("incphp/show_array.php", { posx: "123", posy: "456" } );
}
function ConfirmChoice(gstr)
{
answer = confirm("save?")
	if (answer !=0)
	{
		location = gstr;
	}
}

function preparray2(project_id)  { //lengthArray holds the length of markerArray
//var gstr = '<a href="incphp/show_array.php?project_id='+project_id+'&'; OLD NAME
	//var gstr = '<a href="incphp/update_markers.php?project_id='+project_id+'&';
	//var gstr2 = 'incphp/update_markers.php?project_id='+project_id+'&';
	var gstr2 = 'ed04.php?project_id='+project_id+'&';
	for (i=0;i<lengthArray ;i++ )  {
	var id = markerArray[i][1]; //the stored ident
	var markerx = markerArray[i][2];
	var markery = markerArray[i][3];
	//gstr = gstr+'ident'+i+'='+id+'&x'+i+'='+markerx+'&y'+i+'='+markery+'&';
	gstr2 = gstr2+'ident'+i+'='+id+'&x'+i+'='+markerx+'&y'+i+'='+markery+'&';
	//str1 = (str1 + 'posx'+i+': "'+markerx+'", '+'posy'+i+': "'+markery+'", ');
	
	} //for
	//gstr = gstr+'">click</a>';
	//gstr = '<a href="incphp/show_array.php?project_id=23">click</a>';
	//$('#header').append(gstr); //*****************this
	ConfirmChoice(gstr2);
	//$.post("incphp/show_array.php", { posx: markerx, posy: markery} );
	//str2 = '{ posx0: "100", posy0: "200", posx1: "393", posy1: "364"}';
	//var str2 = '{ posx: "123", posy: "456" }';
	//$('#header').append(str2);
	//$.post("incphp/show_array.php", { strx: markerx, stry: markery} );
}

// function adds a marker, makes draggable and implements drag stop fn to update the array of markers
//if marker is existing it has numeric ident otherwise has been created after array was read as "mark"+i
function addmarker(ident,x,y,icon_image, w, h) {//mkid is the database identifier for the marker
		var style = (' style="position:absolute; left:'+ x +'px;top:'+ y +'px;" ');
		var im = ('<img id="'+ident+'" class="mark" src="'+ icon_image +'" width="'+w+'" height="'+h+'"'+ style +' />');
		//$('#side_panel').append('<p id="' +ident+ '">'+ident+' ' + x +', '+ y + '<p/>');
		$('#map_canvas').append(im);
		//var hash = ('#'+ident);
		var hash = ('.mark');
		// Make Draggable (edit mode)
			$(hash).draggable({
			stop: function(event, ui) {
				var ident = $(this).attr("id");
				//console.log("drag stop triggered event " + ident);
				var n = ident.slice(4); //Now undefined if ident is already existing
				var position = $(this).position();
				var l = position.left;
				var t = position.top ;
		
		//$("p[id=" + ident + "]").html('<p id="' +ident+ '">'+ident+' ' + l +', '+ t + '<p/>'); //updates the side_panel display
		markerArray[n][2] = l; //new dragged values into array but n not defined
		markerArray[n][3] = t;  
		
			} //stop:  
	}); //draggable
} //fn

//set popup Status
var popupStatus=0;
var markerArray = new Array();
var lengthArray = 0; //arraylength
var edit = 1;

$(document).ready(function(){

// gets json file with marker information and passes to an array
	var bg_image = myobj.background['fname'];
	var bg_width = myobj.bg_width['width'];
	var bg_width_str = bg_width+'px';
	var bg_height = myobj.bg_height['height'];
	var bg_height_str = bg_height+'px';
	var icon_image = myobj.markerIcon['fname'];
	var icon_width = myobj.iwidth['width'];
	var icon_height = myobj.iheight['height'];
	var bg_image_string = "url("+bg_image+")";
	var page_title = myobj.title.pagetitle;
	$("#header").html("<h1>" + page_title + "</h1>"); 
		$("#map_canvas").css({"background-image":bg_image_string});  
		$("#map_canvas").css({"height":bg_height_str});
		$("#container").css({"height":bg_height_str});
		$("#header").css({"width":bg_width_str});
		$("#nav").css({"width":bg_width_str});
		$("#map_canvas").css({"width":bg_width_str});
		$("#container").css({"width":bg_width_str});
		$("#footer").css({"width":bg_width_str});


	  $.each(myobj.markers.marker, function(i, item) { //reads existing markers in myobj put in ed04.php from get_markers.php
				var mkid = item.ident;	//pulled from the stored object
				var identity='mark'+i;		//assign local ident
				var posx = item.posx;
				var posy = item.posy;
				markerPoint = new Array(identity, mkid, posx, posy, icon_image, icon_width, icon_height); //create marker element for array
				lengthArray = markerArray.push(markerPoint);//push onto array
				//console.log(ident, mkid, posx, posy, icon_image, icon_width, icon_height);
				addmarker(identity, posx, posy, icon_image, icon_width, icon_height);
		}); //.each

//  binds to a click on the map canvas to add markers
	$('#map_canvas')
		.bind('click',function(ev){
		i = lengthArray;
		var ident = ('mark' + i);
		var posx = ev.pageX - this.offsetLeft;
		var posy = ev.pageY - this.offsetTop;
		//console.log('clicked bg');
		//var icon = "src";//not used yet
		markerPoint = new Array(ident, ident, posx, posy, icon_image, icon_width, icon_height); //create marker element for array
		lengthArray = markerArray.push(markerPoint);				//push onto array
		addmarker(ident,posx,posy,icon_image, icon_width, icon_height);		//mkid for a new marker is same as the ident for the page
		//console.log('clicked bg',ident,posx, posy, icon_image, icon_width, icon_height);
	});  //bind


}); //document ready